package io.bdmc.modules.bss.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.bdmc.common.annotation.FieldMeta;
import io.bdmc.common.utils.Constant;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * <p>
 * 设备基础信息 实体
 * </p>
 *
 * @author ping
 * @since 2020-06-29
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
// "DeviceDevice对象", description = "设备基础信息")
public class DeviceDevice extends Model<DeviceDevice> {

    private static final long serialVersionUID = 1L;

    // "自增Id")
    @TableId(value = "device_id", type = IdType.AUTO)
    private Integer deviceId;

    // "部门id")
    private int deptId;

    // "父id")
    private int parentId;

    // "设备名称")
    @FieldMeta(name = "设备名称", description = "设备名称")
    private String deviceName;

    // "设备型号")
    @FieldMeta(name = "设备型号", description = "设备型号")
    private String deviceModel;

    // "设备摘要")
    @FieldMeta(name = "设备摘要", description = "设备摘要")
    private String deviceDigest;

    // "机架id")
    @FieldMeta(name = "机架id", description = "机架id")
    private Long frameId;

    // "所属层数")
    @FieldMeta(name = "所属层数", description = "所属层数")
    private Integer layerRow;

    // "IP")
    @FieldMeta(name = "IP", description = "IP")
    private String ipaddr;

    // "设备出厂mac地址")
    @FieldMeta(name = "设备出厂mac地址", description = "设备出厂mac地址")
    private String deviceMac;

    // "设备出厂序列号")
    @FieldMeta(name = "设备出厂序列号", description = "设备出厂序列号")
    private String deviceSn;

    // "设备类型")
    @FieldMeta(name = "设备类型", description = "设备类型")
    private String deviceType;

    // "通讯端口号")
    @FieldMeta(name = "通讯端口号", description = "通讯端口号")
    private Integer devicePort;

    // "备注")
    private String remark;

    private String readCode;

    private String writeCode;

    // "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @FieldMeta(name = "创建时间", description = "创建时间")
    private LocalDateTime createTime;

    // "创建人")
    private String createBy;

    @TableField(exist = false)
    private String frameName;

    @TableField(exist = false)
    private String equipmentroomName;

    @TableField(exist = false)
    private String deptName;

    @Override
    public Serializable pkVal() {
        return this.deviceId;
    }

    public boolean isOTDR() {
        return deviceType.equals(Constant.FMSM) || deviceType.equals(Constant.FMSA);
    }

    public boolean isFMS() {
        return deviceType.equals(Constant.FMS);
    }

    public String getOTDRType() {
        if (deviceType.equals(Constant.FMSM) || deviceType.equals(Constant.FMSA)) {
            return Constant.FMSM;
        }
        return Constant.FMS;
    }
}
